//
//  StatusListViewModel.m
//  OC-微博
//
//  Created by Apple on 15/11/13.
//  Copyright © 2015年 Apple. All rights reserved.
//

#import "StatusListViewModel.h"
#import "Status.h"
#import "StatusViewModel.h"
@interface StatusListViewModel()
@property (nonatomic, strong) NSMutableArray *dataList;
@property (nonatomic, strong) StatusViewModel *status;
@end
// 微博数据列表模型 － 封装网络方法
@implementation StatusListViewModel
#pragma mark /*******************  加载数据  *******************/

- (void)loadStatus:(void (^)(BOOL, NSArray *))finished {
    [[NetworkingTools shardTools]loadStatuesInfofinished:^(id result, NSError *error) {
        if (error != nil) {
            NSLog(@"微博信息加载出错了");
            finished(NO,nil);
            return ;
            
        }
        NSMutableArray *array = [NSMutableArray array];
        for (NSDictionary *dict in result[@"statuses"]) {
            [array addObject:dict];
        }
        // 遍历字典的数组，字典转模型;
        //1.创建可变数组
        NSMutableArray *dataList = [NSMutableArray array];
        //2.遍历数组
        for (NSDictionary *dict in array) {
            [dataList addObject:[Status initWithdict:dict]];
           
         // [dataList addObject:[StatusViewModel alloc]init]
         
        }
        
         self.dataList = dataList;
        //完成回调
        finished(YES,self.dataList.copy);
    }];


}

@end
